/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.nextsql.renderizar;

import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class TabelaRender extends DefaultTableCellRenderer {
    //Mostrar qual linha esta marcada
    public void fillColor(JTable table, JLabel label, boolean isSelected) {
        if (isSelected) {
            label.setBackground(table.getSelectionBackground());
            label.setForeground(table.getSelectionForeground());
        } else {
            label.setBackground(table.getBackground());
            label.setForeground(table.getForeground());
        }
    }
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (value instanceof JLabel) {
            JLabel label = (JLabel)value;
            String s[] = label.getName().split("\\|");
            String img[] = s[1].split("\\.");
            if(getClass().getResource("/br/com/nextsql/resources/icons/"+img[0]+".png") != null){
                label.setIcon(new ImageIcon(getClass().getResource("/br/com/nextsql/resources/icons/"+img[0]+".png")));
            }
            label.setOpaque(true);
            fillColor(table, label, isSelected);
            return label;
        }
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
}
